package com.controller
{

	import com.ApplicationFacade;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.command.SimpleCommand;
	import org.puremvc.as3.multicore.utilities.statemachine.FSMInjector;

	public class InjectFSMCommand extends SimpleCommand
	{
		override public function execute(note:INotification):void
		{
			var fsm:XML=
				<fsm initial={ApplicationFacade.WELCOMING}>
					<state name={ApplicationFacade.WELCOMING} 
						changed={ApplicationFacade.SHOW_WELCOME}>
						<transition action={ApplicationFacade.COLLECT} target={ApplicationFacade.COLLECTING}/>
					</state>
					<state name={ApplicationFacade.COLLECTING}
						entering={ApplicationFacade.ENTER_COLLECTING}>
						<transition action={ApplicationFacade.SUBMITED} target={ApplicationFacade.VALIDATING}/>
						<transition action={ApplicationFacade.LOGOUT} target={ApplicationFacade.WELCOMING}/>
					</state>
					<state name={ApplicationFacade.VALIDATING}
						exiting={ApplicationFacade.CONFIRM_LOGOUT}>
						<transition action={ApplicationFacade.VALIDATED} target={ApplicationFacade.SAVING}/>
						<transition action={ApplicationFacade.LOGOUT} target={ApplicationFacade.WELCOMING}/>
					</state>			
					<state name={ApplicationFacade.SAVING}
						changed={ApplicationFacade.SAVE_FORM}>
						<transition action={ApplicationFacade.SAVED} target={ApplicationFacade.THANKING}/>
						<transition action={ApplicationFacade.FAILED} target={ApplicationFacade.FAILING}/>
						<transition action={ApplicationFacade.LOGOUT} target={ApplicationFacade.WELCOMING}/>
					</state>
					<state name={ApplicationFacade.FAILING}
						changed={ApplicationFacade.SHOW_FAILED}>
						<transition action={ApplicationFacade.COLLECT} target={ApplicationFacade.COLLECTING}/>
						<transition action={ApplicationFacade.LOGOUT} target={ApplicationFacade.WELCOMING}/>
					</state>
					<state name={ApplicationFacade.THANKING}
						changed={ApplicationFacade.SHOW_THANKS}>
						<transition action={ApplicationFacade.COLLECT} target={ApplicationFacade.COLLECTING}/>
						<transition action={ApplicationFacade.LOGOUT} target={ApplicationFacade.WELCOMING}/>
					</state>
				</fsm>;

			var injector:FSMInjector=new FSMInjector(fsm);
			injector.initializeNotifier(this.multitonKey); //THIS IS IMPORTANT
			injector.inject();
		}
	}
}